package com.example.demo.service;


import com.example.demo.mapper.LogInfoMapper;
import com.example.demo.model.LogInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;

@Service
public class LogService {

    @Resource
    private LogInfoMapper logInfoMapper;

    //// 表示如果 UserController 中的add3方法存在事务，该add方法就直接加入，若 UserController 中的add3方法不存在事务就新建事务
    @Transactional(propagation = Propagation.REQUIRED)
    public int add(LogInfo logInfo) {
        int result = logInfoMapper.add(logInfo);
        System.out.println("添加日志结果：" + result);
//        try {
        int number = 10 / 0;
//        } catch (Exception e) {
//            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//        }
        return result;
    }
}
